package com.example.demo.service.impl;

import com.example.demo.dataobject.Treatment;
import com.example.demo.dataobject.UserInfo;
import com.example.demo.repository.TreatmentRepository;
import com.example.demo.repository.UserInfoRepository;
import com.example.demo.service.TreatmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TreatmentServiceImpl implements TreatmentService {

    @Autowired
    private UserInfoRepository userInfoRepository;

    @Autowired
    private TreatmentRepository treatmentRepository;

    @Override
    public boolean save(Treatment treatment) {
        Treatment result = treatmentRepository.save(treatment);
        if(result!=null){
            return true;
        }
        return false;
    }

    @Override
    public Treatment findByTelephone(String telephone) {
        UserInfo userInfo = userInfoRepository.findByTelephone(telephone);
        Treatment result = treatmentRepository.findByUserId(userInfo.getId());
        return result;
    }
}
